define(function(require, exports, module) {
	myApp  = seajs.data.vars.myApp;
	$$  = seajs.data.vars.dom;	
	 
	var  publicpagecount =1;
	var  mypagecount = 1;
	

	function page(){
		var _basePage=this;
		this.init=function(){

			var url="/m/customer/list";
			var tabobj =  null;
			var tabobjtwo =  null;
			var tabobjthree = null;
			var tabobjfour = null;
				    
			//企业公共库
			myApp.showTab("#tab1");
			//显示进度条
			var container = $$('body');
			if (container.children('.progressbar, .progressbar-infinite').length) return;
			myApp.showProgressbar(container, 'multi');
			//创建一个vue实例
			tabobj = new Vue({
				el:'#tb1', //为实例提供挂载元素,可以是css选择符,或HTML元素或HTML返回的函数.在实例挂载后,可以使用tabobj.$el访问
				data:{listdata:{},param:{}}, //是vue实例的数据对象,会递归将data的属性转换成getter/setter,对象必须是纯粹ude对象(含有0个或多个的key/value对)
				created:function(){ //实例创建完成后调用,在这里调用ajax获取页面初始化内容
					publicpagecount =1;
					var _self=this;
					$$.ajax({
						url: url,
						method:"POST",
						async:false,
						data:{type:'1', state: '4',skipToPage:publicpagecount},
						success: function(data){
							if(data!=null&&data.length>1){
								//把获取的内容放到data中,传到页面
								_self.listdata=eval("(" + data +")");  
								publicpagecount++;
							}  
						}
					})  
				},
				mounted:function(){ //一个钩子,在el被新建的$el替换并挂载到实例后调用
					setTimeout(function () {
						//隐藏进度条
						myApp.hideProgressbar();
					}, 1000);
				},
				beforeUpdate:function(){ //在数据更新的时候调用,发生在DOM重渲染之前
					//显示进度条
					myApp.showProgressbar(container, 'multi');
				}, 
				updated:function(){ //一个钩子,在数据更改导致DOM重渲染后调用该钩子
					//myApp.hideProgressbar()
				},
				methods: { //方法事件处理,用于写js方法,可以在页面通过v-on调用或用tabobj.方法名调用
					
					//加载并拼接数据
					reloaddata: function (obj) {
						if (container.children('.progressbar, .progressbar-infinite').length) return;  
						myApp.showProgressbar(container, 'multi'); 
							$$.ajax({
								url: url,
								method:"POST",
								async:false,
								data:{type:obj.type, state: obj.state,skipToPage:publicpagecount},
								success: function(data){
									var b= null;
									if(publicpagecount==1){
										b = eval("(" + data +")");
										tabobj.listdata=b; 
										publicpagecount++;
									}else{
										if(data!=null&&data.length>3){
											var a=new Array(); 
											b = a.concat(tabobj.listdata, eval("(" + data +")"));
											tabobjtwo.listdata=b; 
											tabobjtwo.param.skipToPage++;
											tabobj.listdata=b; 
											publicpagecount++;
										}else{
											myApp.toast().show("已全部加载!");
										}
									} 
									setTimeout(function () {
										myApp.hideProgressbar();
									}, 1000);
								}
							})  
					},
					hqbtn:function(type,id){
						alert(publicpagecount);
						hqandfq(type,id,0);
					},
					hsbtn:function(id){
						djhs(id);
					}
				}
			});
			
			//我的企业资源
			tabobjtwo =	new Vue({
				el:'#tb2',
				data:{listdata:{},param:{keyWord:"",type:1,skipToPage:mypagecount ,state:null,csdj:"成熟等级"}},
				created:function(){ 
					mypagecount = 1;
					var _self=this; 
					$$.ajax({
						url: url,
						method:"POST",
						async:false,
						data:_self.param,
						success: function(data){
							if(data!=null&&data.length>1){
								_self.listdata=eval("(" + data +")");
								_self.param.skipToPage++;
							}
						}
					})   
				},
				mounted:function(){
					setTimeout(function () {
						myApp.hideProgressbar();
					}, 1000);
				},
				beforeUpdate:function(){
					//  myApp.showProgressbar(container, 'multi');
				}, 
				updated:function(){
					//myApp.hideProgressbar()
				},
				methods: {
					reloaddata: function (obj) {
						if (container.children('.progressbar, .progressbar-infinite').length) return;  
						myApp.showProgressbar(container, 'multi');  
						$$.ajax({
							url: url,
							method:"POST",
							async:false,
							data:tabobjtwo.param,
							success: function(data){
									var b= null;
									if(tabobjtwo.param.skipToPage==1){
										b = eval("(" + data +")");
										tabobjtwo.listdata=b; 
										tabobjtwo.param.skipToPage++;
									}else{                		  
										if(data!=null&&data.length>3){   
											var a=new Array(); 
											b = a.concat(tabobjtwo.listdata, eval("(" + data +")"));
											tabobjtwo.listdata=b; 
											tabobjtwo.param.skipToPage++;
										}else{
											myApp.toast().show("已全部加载!"); 	 
										} 
									} 
									setTimeout(function () {
										myApp.hideProgressbar();
									}, 1000);
							}
						})  
					},
					search:function(){
						reload();
					},
					fqbtn:function(type,id){
						alert(tabobjtwo.param.skipToPage);
						hqandfq(type,id,1);
					},
					hsbtn:function(id){
						djhs(id);
					}
				}
			});
					
			//人才公共资源
			tabobjthree = new Vue({
				el:'#tb3',
				data:{listdata:{},param:{}},
				created:function(){ 
					publicpagecount =1;
					var _self=this; 
					$$.ajax({
						url: url,
						method:"POST",
						async:false,
						data:{type:'0', state: '4',skipToPage:publicpagecount},
						success: function(data){
							if(data!=null&&data.length>1){
								_self.listdata=eval("(" + data +")");
								publicpagecount++;
							}
						}
					})   
				},
				mounted:function(){
					setTimeout(function () {
						myApp.hideProgressbar();
					}, 1000);
				},
				beforeUpdate:function(){
					myApp.showProgressbar(container, 'multi');
				}, 
				updated:function(){
					//myApp.hideProgressbar()
				},
				methods: {
					reloaddata: function (obj) {
						if (container.children('.progressbar, .progressbar-infinite').length) return;  
						myApp.showProgressbar(container, 'multi');  
						$$.ajax({
							url: url,
							method:"POST",
							async:false,
							data:{type:obj.type, state: obj.state,skipToPage:publicpagecount},
							success: function(data){
								var b = null;
								if (publicpagecount==1){
									b = eval("(" + data +")");
									tabobjthree.listdata=b; 
									publicpagecount++;
								} else {
									if(data!=null&&data.length>3){
										var a=new Array(); 
										b = a.concat(tabobjthree.listdata, eval("(" + data +")"));
										tabobjfour.listdata=b; 
										tabobjfour.param.skipToPage++;
										tabobjthree.listdata=b; 
										publicpagecount++;
									}else{
										myApp.toast().show("已全部加载!");
									}
								}
								setTimeout(function () {
									myApp.hideProgressbar();
								}, 1000);
							}
						})  
					},
					hqbtn:function(type,id){
						alert(publicpagecount);
						hqandfq(type,id,0);
					},
					hsbtn:function(id){
						djhs(id);
					}
				}
			});
					
			tabobjfour = new Vue({
				el:'#tb4',
				data:{listdata:{},param:{keyWord:"",type:0,skipToPage:mypagecount ,state:null,csdj:"成熟等级"}},
				created:function(){
					mypagecount = 1;
					var _self=this; 
					$$.ajax({
						url: url,
						method:"POST",
						async:false,
						data:_self.param,
						success: function(data){
							if(data!=null&&data.length>1){
								_self.listdata=eval("(" + data +")");
								mypagecount++;
							}
						}
					})   
				},
				mounted:function(){
					setTimeout(function () {
						myApp.hideProgressbar();
					}, 1000);
				},
				beforeUpdate:function(){
					//myApp.showProgressbar(container, 'multi');
				}, 
				updated:function(){
					//myApp.hideProgressbar()
				},
				methods: {
					reloaddata: function (obj) {
						if (container.children('.progressbar, .progressbar-infinite').length) return;  
						myApp.showProgressbar(container, 'multi');
						$$.ajax({
							url: url,
							method:"POST",
							async:false,
							data:tabobjfour.param,
							success: function(data){
								var b= null;
								if (tabobjfour.param.skipToPage==1){
									b = eval("(" + data +")");
									tabobjfour.listdata=b; 
									tabobjfour.param.skipToPage++;
								} else {
									if(data!=null&&data.length>3){
										var a=new Array();
										b = a.concat(tabobjfour.listdata, eval("(" + data +")"));
										tabobjfour.listdata=b; 
										tabobjfour.param.skipToPage++;
									} else {
										myApp.toast().show("已全部加载!"); 
									}
								}
								setTimeout(function () {
									myApp.hideProgressbar();
								}, 1000);
							}
						})  
					},
					search:function(){
						reloadone();
					},
					fqbtn:function(type,id){
						alert(tabobjfour.param.skipToPage);
						hqandfq(type,id,1);
					},
					hsbtn:function(id){
						djhs(id);
					}
				}
			});
					
			// 加载flag
			var loading = false; 
			// 注册'infinite'事件处理函数
			$$('#tab1').on('infinite', function () {  
				tabobj.reloaddata({type:1,state:4});  
			});
					
			$$('#tab2').on('infinite', function () {
				tabobjtwo.reloaddata();
			});
					
			$$('#tab3').on('infinite', function () {
				tabobjthree.reloaddata({type:0,state:4});  
			});
			
			$$('#tab4').on('infinite', function () {
				tabobjfour.reloaddata({type:0});
			});
					
			// 下拉刷新页面
			var ptrContent = $$('.customerggk');
			// 添加'refresh'监听器
			ptrContent.on('refresh', function (e) {
				publicpagecount =1;
				tabobj.reloaddata({type:1,state:4});  
				// 模拟2s的加载过程
				setTimeout(function () {
					myApp.pullToRefreshDone(); 
				}, 2000);     
			});
			
			var ptrContenttwo = $$('.customerhzk');
			// 添加'refresh'监听器
			ptrContenttwo.on('refresh', function (e) {
				tabobjtwo.param.skipToPage =1;
				tabobjtwo.reloaddata();  
				// 模拟2s的加载过程
				setTimeout(function () {
					// 加载完毕需要重置
					myApp.pullToRefreshDone();
				}, 2000);
			});
					
			var ptrContentthree = $$('.resumeggk');
			// 添加'refresh'监听器
			ptrContentthree.on('refresh', function (e) {
				// 模拟2s的加载过程
				setTimeout(function () {
					mypagecount =1;
					tabobjthree.reloaddata({type:0,state:4});  
					// 加载完毕需要重置
					myApp.pullToRefreshDone();
				}, 2000);
			});
					
			var ptrContentthree = $$('.resumehzk');
			// 添加'refresh'监听器
			ptrContentthree.on('refresh', function (e) {
				// 模拟2s的加载过程
				setTimeout(function () {
					mypagecount =1;
					tabobjfour.reloaddata();
					// 加载完毕需要重置
					myApp.pullToRefreshDone();
				}, 2000);
			});
					
			$$('#tab1').on('show', function () {
				// myApp.alert('Tab 1 is visible');
			});
						 
			$$('#tab2').on('show', function () {
				// myApp.alert('Tab 2 is visible');
			});
					
			$$('#tab3').on('show', function () {
				// myApp.alert('Tab 1 is visible');
				tabobjthree.reloaddata({type:0,state:4});  
			});
					
			$$('#tab4').on('show', function () {
				// myApp.alert('Tab 1 is visible');
				tabobjfour.search();
			});
					

			var  reload= function(){
				tabobjtwo.param.skipToPage =1;
				tabobjtwo.reloaddata(); 
				setTimeout(function () { 
					// 加载完毕需要重置
					myApp.pullToRefreshDone();
				}, 2000);
			}
			
			var reloadone = function(){
				tabobjfour.param.skipToPage =1;
				tabobjfour.reloaddata();
				setTimeout(function () { 
					// 加载完毕需要重置
					myApp.pullToRefreshDone();
				}, 2000);
			}

			
			
			
			//客户的放弃和获取测试
			//type:人才还是企业,id客户id,sign获取还是放弃
			var hqandfq = function(type,id,sign,pageNo){
				//获取或放弃ajax
				/*$$.ajax({
					type:"post",
					url:"/m/customer/hqfqcustomer",
					data:{type:type,id:id,sign:sign},
					dataType:"json",
					async:false,
					success:function(data){
						if (data == -1) {
							if (type == 0) {
								myApp.toast().show("人才获取失败,已到达可获取上限"); 
							} else {
								myApp.toast().show("企业获取失败,已到达可获取上限"); 
							}
						} else if (data == 2) {
							myApp.toast().show("放弃失败,该人才已绑定合同"); 
						} else {
							if (sign == 0) {
								myApp.toast().show("获取成功"); 
							} else {
								myApp.toast().show("放弃成功"); 
							}
						}
					}
				});*/
				//操作成功后要重新加载数据
				/*setTimeout(function () {
					if (type==1 && sign== 0) {
						//企业获取
						publicpagecount =1;
						tabobj.reloaddata({type:1,state:4}); 
					} else if (type == 1 && sign == 1) {
						//企业放弃
						tabobjtwo.param.skipToPage =1;
						tabobjtwo.reloaddata(); 
					} else if (type == 0 && sign == 0) {
						//人才获取
						publicpagecount =1;
						tabobjthree.reloaddata({type:0,state:4});
					} else {
						//人才放弃
						tabobjfour.param.skipToPage =1;
						tabobjfour.reloaddata(); 
					}
					// 加载完毕需要重置
					myApp.pullToRefreshDone();
				}, 2000);*/
			}
			
			//点击回收
			var djhs = function(id){
				$$.ajax({
					type:"post",
					url:"/m/customer/recyclebinsave",
					data:{id:id},
					dataType:"json",
					async:false,
					success:function(data){
						if(data=="1"){
							myApp.toast().show("申请放入回收站成功");
							reload();
						}else{
							myApp.toast().show("申请放入回收站失败");
						} 
					}
				});
			}
			
			
			
			
			
			$$('.ac-2').on('click', function () {
				var buttons = [
				{
					text: '成熟等级',    
					onClick: function () {
						tabobjtwo.param.state = null;
						tabobjtwo.param.csdj ='成熟等级';
						reload();
					}
				},
				{
					text: '意向不明',
					color:'gray',
					onClick: function () {
						tabobjtwo.param.state = 1;
						tabobjtwo.param.csdj ='意向不明';
						reload();
					}
				},
				{
					text: '意向明确',
					color:'gray',
					onClick: function () {
						tabobjtwo.param.state = 6;
						tabobjtwo.param.csdj ='意向明确';
						reload();
					}
				},
				{
					text: '意向强烈',
					color:'gray',
					onClick: function () {
						tabobjtwo.param.state = 5;
						tabobjtwo.param.csdj ='意向强烈';
						reload();
					}
				},
				{
					text: '合作客户',
					color:'gray',
					onClick: function () {
						tabobjtwo.param.state = 7;
						tabobjtwo.param.csdj ='合作客户';
						reload();
					}
				},
				];
				myApp.actions(buttons);
			});	
			
			$$('.ac-3').on('click', function () {
				var buttons = [
				{
					text: '成熟等级',    
					onClick: function () {
						tabobjfour.param.state = null;
						tabobjfour.param.csdj ='成熟等级';
						reloadone();
					}
				},
				{
					text: '意向不明',
					color:'gray',
					onClick: function () {
						tabobjfour.param.state = 1;
						tabobjfour.param.csdj ='意向不明';
						reloadone();
					}
				},
				{
					text: '即将到期',
					color:'gray',
					onClick: function () {
						tabobjfour.param.state = 2;
						tabobjfour.param.csdj ='即将到期';
						reloadone();
					}
				},
				{
					text: '即将到期',
					color:'gray',
					onClick: function () {
						tabobjfour.param.state = 3;
						tabobjfour.param.csdj ='随时可挂';
						reloadone();
					}
				},
				{
					text: '合作客户',
					color:'gray',
					onClick: function () {
						tabobjfour.param.state = 7;
						tabobjfour.param.csdj ='合作客户';
						reloadone();
					}
				},
				];
				myApp.actions(buttons);
			});
		};
	}		
	module.exports=new page();
})


